﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Shanda.Utility;
using Common;

namespace WebSite.Core
{
    /// <summary>
    ///ServiceBase 的摘要说明
    /// </summary>
    public class ServiceBase : BasePage, IHttpHandler, System.Web.SessionState.IRequiresSessionState
    {
        public ServiceBase()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }

        public void ProcessRequest(HttpContext context)
        {
            context.Response.Buffer = true;
            context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            context.Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
            context.Response.Expires = 0;
            context.Response.CacheControl = "no-cache";
            context.Response.Cache.SetNoStore();
            context.Response.ContentType = "text/plain";
            string resultStr = DoProcess(context);
            if (string.IsNullOrEmpty(resultStr))
            {
                resultStr = DefaultProcess();
            }
            context.Response.Write(resultStr);
        }

        protected virtual string DoProcess(HttpContext context)
        {
            var ret = RetInfo.DefaultError(-99, "未实现");
            return ret.SerializeToString(Common.Serialization.SerializationType.Json);
        }

        protected string DefaultProcess()
        {
            var ret = RetInfo.DefaultError(-99, "未处理");
            return ret.SerializeToString(Common.Serialization.SerializationType.Json);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}